class Solution(object):
    def findLonelyPixel(self, picture):
        """
        :type picture: List[List[str]]
        :rtype: int
        """
        m = len(picture)
        n = len(picture[0])
        already_grid = [[0 for _ in range(n)] for _ in range(m)]
        total = 0
        for i in range(m):
            for j in range(n):
                if picture[i][j] == 'B' and already_grid[i][j] == 0:
                    count = 0
                    for k in range(n):
                        if picture[i][k] == 'B':
                            already_grid[i][k] = 1
                            count += 1
                    for k in range(m):
                        if picture[k][j] == 'B':
                            already_grid[k][j] = 1
                            count += 1
                    if count == 2:
                        total += 1
        return total


data = Solution()
picture = [["W", "W", "B"], ["W", "B", "W"], ["B", "W", "W"]]
print(data.findLonelyPixel(picture))
picture = [["B", "B", "B"], ["B", "B", "W"], ["B", "B", "B"]]
print(data.findLonelyPixel(picture))
